/*
 * Copyright (c) 2004-2022, University of Oslo
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors 
 * may be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.hisp.dhis.render.type;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.hisp.dhis.common.DxfNamespaces;

/**
 * This class represents the DataElement/TrackedEntityAttribute ValueType based rendering type
 *
 * <p>The min, max, step and decimal properties in this class does not represent the data
 * validation, it only serves as a guideline on how form elements should be defined (IE: Sliders,
 * spinners, etc)
 */
public class ValueTypeRenderingObject implements RenderingObject<ValueTypeRenderingType> {
  /** The renderingType */
  private ValueTypeRenderingType type;

  // For numerical types

  /** The minimum value the numerical type can be */
  private Integer min;

  /** The maximum value the numerical type an be */
  private Integer max;

  /** The size of each step in the form element */
  private Integer step;

  /** The number of decimal points that should be considered */
  private Integer decimalPoints;

  // ------------------------------------------
  // Constructors
  // ------------------------------------------

  public ValueTypeRenderingObject() {
    this.type = ValueTypeRenderingType.DEFAULT;
  }

  public ValueTypeRenderingObject(ValueTypeRenderingType type) {
    this.type = type;
  }

  // ------------------------------------------
  // Getters & Setters
  // ------------------------------------------

  @JsonProperty
  @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
  public Integer getDecimalPoints() {
    return decimalPoints;
  }

  public void setDecimalPoints(Integer decimalPoints) {
    this.decimalPoints = decimalPoints;
  }

  @JsonProperty
  @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
  public Integer getStep() {
    return step;
  }

  public void setStep(Integer step) {
    this.step = step;
  }

  @JsonProperty
  @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
  public Integer getMax() {
    return max;
  }

  public void setMax(Integer max) {
    this.max = max;
  }

  @JsonProperty
  @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
  public Integer getMin() {
    return min;
  }

  public void setMin(Integer min) {
    this.min = min;
  }

  @Override
  @JsonProperty
  @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
  public ValueTypeRenderingType getType() {
    return type;
  }

  @Override
  public void setType(ValueTypeRenderingType renderingType) {
    this.type = renderingType;
  }

  @Override
  @JsonIgnore
  public Class<ValueTypeRenderingType> getRenderTypeClass() {
    return ValueTypeRenderingType.class;
  }
}
